package com.titaniume.rqbbitmq.eight;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import com.titaniume.rqbbitmq.util.RabbitMqUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * @program: rqbbitmq-hello
 * @description: 死信队列  消费者C2
 * @author: titaniume
 * @create: 2021-12-23 08:48
 */
public class Comsumer02 {

    //死信交换机名称
    private static final String DEAD_EXCHANGE = "dead_exchange";
    //死信队列名称
    private static final String DEAD_QUEUE = "dead_queue";
    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMqUtils.getChannel();
        //声明死信和 类型为Direct
        channel.exchangeDeclare(DEAD_EXCHANGE,BuiltinExchangeType.DIRECT);
        //声明死信队列
        channel.queueDeclare(DEAD_QUEUE,false,false,false,null);
        //绑定死信交换机和死信队列
        channel.queueBind(DEAD_QUEUE,DEAD_EXCHANGE,"lisi");
        System.out.println("等待接收消息...");
        DeliverCallback deliverCallback = (consumerTag,message)->{
            System.out.println("Comsumer02接收到消息:"+new String(message.getBody(),"UTF-8"));
        };
        //接收消息
        channel.basicConsume(DEAD_QUEUE,true,deliverCallback,consumerTag->{});
    }
}